package com.example.mapper;

import com.example.entity.Collect;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CollectMapper {

    /**
     * 新增
     */
    int insert(Collect collect); //可以让新增之后，将id进行返回

    /**
     * 更新
     */
    void updateById(Collect collect);

    /**
     * 删除
     */
    @Delete("delete from collect where id = #{id}")
    void deleteById(Integer id);

    /**
     * 查询所有
     */
    List<Collect> selectAll(Collect collect);

    /**
     * 批量删除
     */
    void deleteBatch(@Param("ids") List<Integer> ids);

    /**
     * 根据id查询
     */
    @Select("select * from collect where id = #{id}")
    Collect selectById(Integer id);

    /**
     * 查询用户收藏信息
     */
    @Select("select * from collect where user_id = #{userId} and fid = #{fid}")
    Collect selectUserCollect(@Param("userId") Integer userId, @Param("fid") Integer fid);

    /**
     * 查询当前攻略的收藏量
     */
    @Select("select count(*) from collect where fid = #{fid}")
    Integer selectCountByFid(Integer fid);
}
